package com.xiaoyu.lanling.event.generosity

import `in`.srain.cube.request.JsonData
import com.xiaoyu.base.event.BaseJsonEvent
import com.xiaoyu.base.utils.ListUtil
import com.xiaoyu.lanling.event.charming.LevelUpMeansItem
import com.xiaoyu.lanling.media.image.ImageLoadParam

class GenerosityLevelEvent(requestTag: Any, jsonData: JsonData) : BaseJsonEvent(requestTag, jsonData) {
    val level = "Lv." + jsonData.optString("level")
    val nextLevel = "Lv." + (jsonData.optInt("level") + 1).toString()
    val value = jsonData.optInt("value")
    val nextLevelValue = jsonData.optInt("nextLevelValue", 1000000)
    var rest = nextLevelValue - value

    // fallback 100000 in case div zero
    val progress = (value * 100) / nextLevelValue
    val icon = jsonData.optString("iconUrl")
    val iconLoadParam = ImageLoadParam.newBuilder().setUrl(icon)
            .setWidthInDP(80)
            .setHeightInDP(24)
            .build()
    val list = ListUtil.convertToList(jsonData.optJson("list").toList()) { LevelUpMeansItem(it) }
}